//菜单管理
$(function(){
	//初始化列表
	$("#menuList").getChannelList({
		"initData":{ //默认参数配置
			size:''
		},
		"url":site.apiUrl + "/menu/selectMenuListByPageByThis",
		"type":"post",
		"ajaxform":true,
		"col":[  //数据列
			{"field":"menuName","display":"菜单标题","width":"2"},
			{"field":"menuCode","display":"菜单编码","width":"1"},
			{"field":"icon","display":"菜单图标","width":"2","fun":"changePic"},
			{"field":"menuNameNext","display":"父级","width":"2","fun":"changeMenuNameNext"},
			{"field":"parentNum","display":"下级数量","width":"1"},
			{"field":"nodeOrder","display":"显示顺序","width":"1"},
		    {"field":"isUsing","display":"状态","show":[  //数据自定义显示
			    {"value":"1","html":"启用"},
			    {"value":"0","html":"禁用"}
	      	]},
	    ],
		"option":[ //操作按钮配置
	    		{"icon":"add","tip":"添加下级菜单","url":"add-menu.html?pid={{id}}"},  //icon: view,edit,add,delicon: view,edit,add,del
	     		{"icon":"edit","tip":"编辑","url":"add-menu.html?id={{id}}"},  // 花括号内可以对应相关字段
	     		{"icon":"del","tip":"删除","fun":"deleteMenu('{{id}}',this)"},
	     	]
	    });
});

//显示图片
function changePic(v, o, d) {
	$(o).html("<i class='iconfont "+d.icon+"'></i>"); 
	var selecter = $(o).parents("tr").find("td:last ul");
	if(d.level==3){
   		$(selecter).find("li.add").remove();
	}

}

//下级数量
function changeMenuNameNext(v, o, d) {
   // $(o).html("<img src='"+$($(o).html()).html()+"' width='30' height='30'>");
   var i =d.menuNameNext;
   if(i!=null && i != '' && i !='undefined'){
   	$(o).html("<i class='lm-expand pl10'>"+i+"</i>")
   }else{
   	$(o).html("<i class='lm-expand'>顶级菜单</i>")
   }
   
}

//删除
function deleteMenu(id,obj){
	var _this = $(obj);
	var deleteUserId = window.sessionStorage.getItem("backstage-access-id");
	var obj = {
		'id':id,
		'deleteUserId':deleteUserId
	};
	var url = site.apiUrl+"/menu/deleteMenuByThis";
	ly.confirm("你确定删除吗？",function(){
		request({
	        url: url,
	        data:obj,
    		ajaxform:true,
	        type: 'POST',
	        callback: function(r) {
				if(r.code=="rest.success"){
					ly.toast('删除成功');
					$(_this).parents("tr").remove();
	        	}else{
	        		ly.toast(r.msg);
	        	}
	        }
		});
	});
}

